<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://www.ufida.com/lfw" prefix="lfw" %>
<%@ taglib uri="http://www.ufida.com/uif" prefix="uif" %> 
<%@ taglib uri="http://www.ufida.com/lfwtool" prefix="lfwtool" %> 
<%@ taglib uri="http://www.ufida.com/multilang" prefix="ml" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@page import="nc.lfw.core.LfwRuntimeEnvironment"%>
<%@page import="nc.lfw.billtemplate.controller.ILfwControllerBase"%>
<%@page import="nc.lfw.billtemplate.controller.IManageControllerBase"%>
<html> 
	<head>
		<lfw:base/>
		<lfw:head/> 
		<lfw:import/>
		<uif:webbximport/>
		<script type='text/javascript' src='${ROOT_PATH}/html/nodes/report/balancscript.js'></script>
		<script type='text/javascript' src='${ROOT_PATH}/html/nodes/report/reportutils.js'></script>
	</head>
	<body bottommargin="0" topmargin="0" leftmargin="0" rightmargin="0" scroll=no onload="pageBodyScript()">
		<lfw:pageModel className="nc.lfw.finance.report.model.ExpenseBalanceReportPageModel" showLoadingPage="false">
			<lfw:layout type="border">
				<lfw:layoutPanel position="top" height="50">
					<lfw:menubar id="menubar"></lfw:menubar>
				</lfw:layoutPanel>
				<lfw:layoutPanel position="center">
					<lfw:spliter divideSize="60" boundMode="px" id="spliter1" orientation="v">
						<lfw:spliterPanelOne>
							<lfw:form id="headForm"></lfw:form>
						</lfw:spliterPanelOne>
						<lfw:spliterPanelTwo>
							<lfw:grid id="bodyGrid" />
						</lfw:spliterPanelTwo> 
					</lfw:spliter>	
				</lfw:layoutPanel>
			</lfw:layout>
		</lfw:pageModel>
	</body>
</html>
<script Language="JavaScript">

function externalInit()
{ 
	var headDs = getDataset('headDataset');
	headDs.setValueAt(0, headDs.nameToIndex("showtype"), "0");
	headDs.setValueAt(0, headDs.nameToIndex("booktype"), "0");

	var grid = getComponent("bodyGrid");
	if(grid != null)
	{
		grid.outerDiv.style.borderRight = "none";
		grid.outerDiv.style.borderLeft = "none";
		grid.outerDiv.style.borderBottom = "none";
		setGridVisibleHeaders(null, 0, null);
	}

	var menubar = getComponent("menubar");
	if(menubar != null)
	{
		menubar.Div_gen.style.borderTop = "none";
		menubar.Div_gen.style.borderLeft = "none";
		menubar.Div_gen.style.borderRight = "none";
	} 
	adjustSpliter();
	var action = '<%=request.getParameter("triggertype")%>';
	if(action == 'qrybalance' ){
		var loader = new DatasetLoader(getDataset('bodyDataset'));
		loader.setKeyValue(Dataset.MASTER_KEY);
		loader.load();
	}
	var qryObj_str = getSessionAttribute('detail_query_condition');
	var v_map = getSessionAttribute('detail_v_map');
	var other_map = getSessionAttribute('detail_other_map');
	saveQryCondition(qryObj_str,v_map,other_map,false);
	
	var vMap = getMap(v_map);
	var otherMap = getMap(other_map);
  	if(vMap != null && otherMap != null){
  		repaintForm(vMap,otherMap);
  		saveMap(v_map,other_map);
	  }
}



function JkbxLocalJeRender(){};
JkbxLocalJeRender.render = function(rowIndex, colIndex, value, header, cell)
{
	cell.style.overflow = "hidden";
	cell.style.textOverflow = "ellipsis";
	cell.style.cursor = "default";
	cell.style.textAlign = "center";
	
	if(value == null)
		value = '0.00';
	
	var grid = header.owner;
	var ds = grid.model.dataset;
	var gridRow = grid.getRow(rowIndex);
	var row = gridRow.getRowData();
	var pre = parseInt(row.getCellValue(ds.nameToIndex('report_local_pre')));
	value  = getValue4Precision(pre,value);
	cell.innerHTML  = "<center>" + value + "<center>" ;
}
/********************/
function JkbxJeRender(){};
JkbxJeRender.render = function(rowIndex, colIndex, value, header, cell)
{
	cell.style.overflow = "hidden";
	cell.style.textOverflow = "ellipsis";
	cell.style.cursor = "default";
	cell.style.textAlign = "center";
	
	if(value == null || value == '')
		value = '0.00';
	
	var grid = header.owner;
	var ds = grid.model.dataset;
	var gridRow = grid.getRow(rowIndex);
	var row = gridRow.getRowData();
	var pre = parseInt(row.getCellValue(ds.nameToIndex('report_pre')));
	value  = getValue4Precision(pre,value);
	cell.innerHTML  = "<center>" + value + "<center>" ;
}
function getValue4Precision(pre,value){
	
	if(value.indexOf(".") == -1){
		value += ".";
		for(var i=0; i<pre; i++)
			value += "0";
	}else if(parseFloat(value) == 0){//值为0
		value = "0.";
		for(var i=0; i<pre; i++)
			value += "0";
	}else{//正常浮点数
		value = getDoubleByTrimZero(value);
		if(value.indexOf(".") == -1){
			value += ".";
			for(var i=0; i<pre; i++)
				value += "0";
		}else{
			var arr = value.split(".");
			var c = pre - parseInt(arr[1].length);
			if(c > 0){
				for(var i=0; i<c; i++)
					value += "0";				
			}
		}
	}
	return value;
};
/*去掉0*/
function getDoubleByTrimZero(value){
	var index = -1;
	var count = value.length-1;
	for(var i=count;i>=0;i--){
		var ch = value.substring(i-1,i);
		if(ch == '.'){
			index = i-1;
			break;	
		}else if(ch != '0'){
			index = i;
			break;	
		}
	}
	return (index == -1) ? value : value.substring(0,index) ;
}
</script>